package com.fulihui.wgj.admin.api.labels;

import com.fulihui.common.result.web.Result;
import com.fulihui.wgj.admin.api.base.BaseController;
import com.fulihui.wgj.admin.api.labels.request.LabelsSaveRequest;
import com.fulihui.wgj.admin.api.labels.vo.LabelsVO;
import com.fulihui.wgj.admin.integration.LabelInfoServiceClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * @author: Levon
 * @date: 2018-07-09 15:42
 */
@RestController
@RequestMapping("/labels")
@Api(tags = "用户标签")
public class LabelsController extends BaseController {

    @Autowired
    private LabelInfoServiceClient labelInfoServiceClient;

    @PostMapping("/list")
    @ApiOperation("获取用户标签列表")
    public Result<List<LabelsVO>> labelList() {
        return labelInfoServiceClient.queryAll();
    }

    @PostMapping("/create")
    @ApiOperation("新增用户标签")
    public Result<String> create(@RequestBody @Valid LabelsSaveRequest request, BindingResult validResult) {
        Result valid = valid(validResult);
        if (Objects.nonNull(valid)) {
            return valid;
        }
        return labelInfoServiceClient.save(request);
    }
}
